<!--
 * @Author: your name
 * @Date: 2022-01-11 17:55:22
 * @LastEditTime: 2022-01-11 18:36:19
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \campus-market-frontend-master\src\pages\about.vue
-->
<route lang="yaml">
meta:
  requiresAuth: true
</route>

<template>
  <div class="about">
    <pre>{{ userData }}</pre>
    <pre>{{ errors }}</pre>
    <button @click="logout">Logout</button>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from '../store'
import { useErrors } from '../composable/useErrors'
import { getUserProfile } from '../services/auth'

const userData = ref({})
const store = useStore()
const router = useRouter()
const { errors, errorHandler } = useErrors()

async function logout() {
  await store.dispatch('logout')
  await router.push('/auth/login')
}

onMounted(async () => {
  try {
    const response = await getUserProfile()
    userData.value = response.data
  } catch (err) {
    errorHandler(err)
  }
})
</script>
